Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support stlink v2 isol variant #1720

Merged

Conversation

HrMitrev
Copy link
Contributor

@HrMitrev HrMitrev commented Jan 9, 2024

Detailed description

The stlink-isol-v2 variant differs from other stlink-v2 variants with how the SWDIO pin is multiplexed. This commit adds support for it. I have tested the commit on my STlink ISOL and it seems to work fine.

Your checklist for this pull request

  • I've read the Code of Conduct
  • I've read the guidelines for contributing to this repository
  • It builds for hardware native (make PROBE_HOST=native)
  • It builds as BMDA (make PROBE_HOST=hosted)
  • I've tested it to the best of my ability
  • My commit messages provide a useful short description of what the commits do

Closing issues

N/A

@dragonmux dragonmux added this to the v2.0 release milestone Jan 9, 2024
@dragonmux dragonmux added the Foreign Host Board Non Native hardware to runing Black Magic firmware on label Jan 9, 2024
Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've got two queries that could do with being answered, and then this looks like it's good to merge.

Please fix your commit message's prefix to conform to the contrib guidelines - in this case, it should be prefixed stlink: as that's the platform all these changes are in.

src/platforms/stlink/stlink_common.c Show resolved Hide resolved
src/platforms/stlink/platform.h Outdated Show resolved Hide resolved
Copy link
Contributor

@ALTracer ALTracer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are macro naming questions from me and a proposal to bring feature parity with SWCLK Hi-Z, which leads into considerations about drive contention somewhere on the PCB. I cannot "Review -1/+1" as I am not a maintainer, and I am very unlikely to get my hands on an ISOL, but you could test anything before the PR is merged, and other less knowledgable users started (hypothetical worst case scenario) damaging their boards.
I assume you already live-tested your PR branch build on a unit?

Comment on lines +57 to +64
/* PB12 is SWDIO_IN */
gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO12);
/* PA4 is used to set SWDCLK floating when set to 1 */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
gpio_clear(GPIOA, GPIO4);
/* PA1 is used to set SWDIO floating and MUXED to SWDIO_IN when set to 1 */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted to, you could implement feature parity with BMP v2.3 HW rev 6 w.r.t. floating the SWCLK pin, required to support stm32g0 in small pin-count packages. See Issue 945 and PR1192 (intentional not-a-mention), specifically commit a573c26 for native platform.
PB12 is T_SWDIO_IN on most/all stlinkv2 schematics, and you made it a macro -- please substitute it into here (SWDIO_IN_PIN).
Accordingly, PA4 sounds like TCK_DIR_PIN and PA1 like TMS_DIR_PIN/SWDIO_DIR_PIN. This makes for less unused/magic pin numbers, even if you described their purpose in adjacent comments (nice!).

Comment on lines +84 to +87
#ifdef STLINK_V2_ISOL
/* In case of ISOL variant, this pin is never set to high impedance */
gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if that's true -- PB14 being T_JTMS (effectively T_SWDIO_OUT) was toggled to become input across BMF previously. Do you think PB14 forcing high/low SWDIO in no way interferes with receiving data on PB12 across the isolation circuitry? Although I don't have the exact schematics and don't know where the 100R between SWDIO_IN & SWDIO_OUT resides for ISOL PCB. But you seem to have the means to test it with live targets.

src/platforms/stlink/platform.h Outdated Show resolved Hide resolved
src/platforms/stlink/stlink_common.c Show resolved Hide resolved
@HrMitrev HrMitrev force-pushed the feature/support-stlink-v2-isol branch from 0d476c2 to b85f431 Compare January 20, 2024 13:28
@HrMitrev
Copy link
Contributor Author

HrMitrev commented Jan 20, 2024

Ideally this and the clear below would use the unpacked/inlined version of the code this calls, but this works.

I have unpacked/inlined the mode switch of SWDIO and confirmed to be working on my isol probe. Also I have rebased. Currently I have used this patch for more than 2 weeks every day and my probe seems to be going strong. I haven't had the chanse to confirm it is working with JTAG instead of SWD. In the future if I have more time and HW to test JTAG I will revisit. For now I think this can be merged

Cheers!

Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for tweaking and sorting that. We'll get this merged once the builds complete - thank you for the contribution!

@HrMitrev
Copy link
Contributor Author

HrMitrev commented Jan 20, 2024

About the SWDIO multiplexing - the probe uses Si8420BB RF isolators which are fixed direction. If we ignore the isolators the schematic looks like this: image PB14 and PA1 are always forced to output and PB12 is always forced to input because of the unidirectional RF isolators used to interface between the 2G125 IC and the STM32F01

SWDCLK should be similar, but I think PA4 is used to enable the output propagation or set it to high impedance

This was hidden after the changes, but may be a good idea to be easily accessible

Also it may be useful to provide the build command used - make PROBE_HOST=stlink STLINK_V2_ISOL=1 Optionally you can opt to reflash the bootloader and add RTT support - make PROBE_HOST=stlink ENABLE_RTT=1 BMP_BOOTLOADER=1 STLINK_V2_ISOL=1

@dragonmux dragonmux merged commit 88b132e into blackmagic-debug:main Jan 20, 2024
17 checks passed
@HrMitrev HrMitrev deleted the feature/support-stlink-v2-isol branch January 20, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Foreign Host Board Non Native hardware to runing Black Magic firmware on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants